package craky.componentc;

import java.awt.Color;

import javax.swing.BoundedRangeModel;
import javax.swing.JSlider;
import javax.swing.border.EmptyBorder;

import com.abigdreamer.swing.component.UIUtil;

public class JCSlider extends JSlider
{
  private static final long serialVersionUID = -1988588632695957051L;
  private CSliderUI ui;
  private Color majorTickColor;
  private Color minorTickColor;
  private boolean miniMode;

  public JCSlider()
  {
    this(0, 0, 100, 50);
  }

  public JCSlider(int orientation)
  {
    this(orientation, 0, 100, 50);
  }

  public JCSlider(int min, int max)
  {
    this(0, min, max, (min + max) / 2);
  }

  public JCSlider(int min, int max, int value)
  {
    this(0, min, max, value);
  }

  public JCSlider(int orientation, int min, int max, int value)
  {
    super(orientation, min, max, value);
    init();
  }

  public JCSlider(BoundedRangeModel brm)
  {
    super(brm);
    init();
  }

  private void init()
  {
    this.majorTickColor = new Color(76, 181, 237);
    this.minorTickColor = new Color(78, 160, 209);
    setUI(this.ui = new CSliderUI());
    setFont(UIUtil.getDefaultFont());
    setBackground(Color.GRAY);
    setForeground(new Color(0, 28, 48));
    setOpaque(false);
    setBorder(new EmptyBorder(0, 0, 0, 0));
  }

  public Color getMajorTickColor()
  {
    return this.majorTickColor;
  }

  public void setMajorTickColor(Color majorTickColor)
  {
    this.majorTickColor = majorTickColor;
    repaint();
  }

  public Color getMinorTickColor()
  {
    return this.minorTickColor;
  }

  public void setMinorTickColor(Color minorTickColor)
  {
    this.minorTickColor = minorTickColor;
    repaint();
  }

  public boolean isMiniMode()
  {
    return this.miniMode;
  }

  public void setMiniMode(boolean miniMode)
  {
    this.miniMode = miniMode;
    this.ui.calculateGeometry();
    repaint();
  }

  @Deprecated
  public void updateUI()
  {
  }
}